package ca.psquared.superbrixgame;

import org.newdawn.slick.Graphics;

public class ScoreCounter {

    private static final int SPEED_SLOW = 1;
    private static final int SPEED_FAST = 2;
    private static final int ONE_LINE_INCREMENT = 40;
    private static final int TWO_LINE_INCREMENT = 100;
    private static final int THREE_LINE_INCREMENT = 300;
    private static final int FOUR_LINE_INCREMENT = 1200;

    private int score = 0;
    private int lines = 0;
    private int counter;
    private int speedMultiplier = SPEED_SLOW;


    public void beginCount() {
        counter = 0;
    }

    public void addLineCleared() {
        counter++;
    }

    public void endCount() {
        final int increment;

        switch (counter) {
            case 0: {
                increment = 0;
                break;
            }
            case 1: {
                increment = ONE_LINE_INCREMENT;
                break;
            }
            case 2: {
                increment = TWO_LINE_INCREMENT;
                break;
            }
            case 3: {
                increment = THREE_LINE_INCREMENT;
                break;
            }
            case 4: {
                increment = FOUR_LINE_INCREMENT;
                break;
            }
            default: {
                throw new IllegalStateException("Invalid counter:" + counter);
            }
        }
        score += increment * speedMultiplier;
        lines += counter;

    }

    public void setPieceSpeedSlow() {
        speedMultiplier = SPEED_SLOW;
    }

    public void setPieceSpeedFast() {
        speedMultiplier = SPEED_FAST;
    }

    public void render(Graphics graphics) {
        graphics.drawRect(0, 0, 150, 150);
        graphics.drawString("Lines: " + lines, 30, 50);
        graphics.drawString("Score: " + score, 30, 100);

    }
}
